package com.imooc.service.impl;

import com.imooc.dataobject.SellerInfo;
import com.imooc.enums.ResultEnum;
import com.imooc.exception.SellException;
import com.imooc.repository.SellerInfoRepository;
import com.imooc.service.SellerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 功能描述: <br>
 * (卖家系统用户模块Service)
 *
 * @Author:Mr. xyb
 * @Date: 2018/5/18 17:22
 * @since: 1.8.0
 * @version: 1.0.0
 */
@Service
@Slf4j
public class SellerServiceImpl implements SellerService {

    @Autowired
    private SellerInfoRepository repository;

    /**
     * 根据openid查询用户信息
     *
     * @param openid
     * @return
     */
    @Override
    public SellerInfo findSellerInfoByOpenid(String openid) {
        // 查询用户信息
        SellerInfo sellerInfo = repository.findByOpenid(openid);
        if (sellerInfo == null) {// 用户信息为空则登录失败
            throw new SellException(ResultEnum.LOGIN_FAIL);
        }
        return sellerInfo;
    }
}
